<!-- 辅导员考核结果页面 -->
<template>
  <div class="app-container">
    <!-- 搜索 -->
    <searchForm
      :formOptions="formOptions"
      @onSearch="onSearch"
      @onReset="onReset"
      :formLabelWidth="formLabelWidth"
      v-show="showSearch"
    />
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="uploadVisible = true"
          >导入</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table :data="roleList">
      <el-table-column label="工号" prop="roleName" align="center" />
      <el-table-column label="姓名" prop="roleKey" align="center" />
      <el-table-column label="任职单位" prop="roleSort" align="center" />
      <el-table-column label="考核年度" prop="roleSort" align="center" />
      <el-table-column label="考核资料" prop="roleSort" align="center" />
      <el-table-column label="考核级别" prop="roleSort" align="center" />
      <el-table-column label="千分制" prop="roleSort" align="center" />
      <el-table-column label="百分制" prop="roleSort" align="center" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="220"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改辅导员考核信息 -->
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="考核年度" prop="nickName">
              <el-input placeholder="请输入名称" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="辅导员" prop="nickName">
              <el-input placeholder="请输入辅导员姓名" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="千分制" prop="nickName">
              <el-input placeholder="请输入" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="百分制" prop="nickName">
              <el-input placeholder="请输入" maxlength="30" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考核级别" prop="roleName">
              <el-select
                v-model="form.value1"
                multiple
                placeholder="请选择考核级别"
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.sys_normal_disable"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考核资料">
              <el-input disabled style="width: 77%; float: left" />
              <el-upload class="upload-demo" action="" @change="handlePreview">
                <el-button size="small">点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="导入辅导员信息"
      :visible.sync="uploadVisible"
      width="60%"
      append-to-body
    >
      <el-form ref="uploadInfor" :model="uploadInfor" label-width="140px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="辅导员信息考核模板">
              <el-input disabled style="width: 85%; float: left" />
              <el-upload class="upload-demo" action="" @change="handlePreview">
                <el-button size="small">点击上传</el-button>
              </el-upload>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRole,
  getRole,
  delRole,
  addRole,
  updateRole,
  dataScope,
  changeRoleStatus,
  deptTreeSelect,
} from "@/api/system/role";
import {
  treeselect as menuTreeselect,
  roleMenuTreeselect,
} from "@/api/system/menu";
import searchForm from "@/components/Search/searchForm.vue";
export default {
  name: "Role",
  dicts: ["sys_normal_disable"],
  components: { searchForm },
  data() {
    return {
      formLabelWidth: "70px",
      formOptions: [
        {
          label: "工号",
          prop: "GH",
          element: "el-input",
          placeholder: "请输入工号",
        },
        {
          label: "姓名",
          prop: "XM",
          element: "el-input",
          placeholder: "请输入姓名",
        },
        {
          label: "任职单位",
          prop: "XM",
          element: "el-input",
          placeholder: "请输入任职单位",
        },
        {
          label: "考核级别",
          prop: "XM",
          element: "el-input",
          placeholder: "请输入姓名",
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [{ roleKey: "ceshi" }],
      // 弹出层标题
      title: "",
      // 上传辅导员信息数据
      uploadInfor: {},
      // 是否显示弹出层
      open: false,
      uploadVisible: false,
      // 日期范围
      dateRange: [],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询角色列表 */
    getList() {
      this.loading = true;
      listRole(this.addDateRange(this.queryParams, this.dateRange)).then(
        (response) => {
          this.roleList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 获取搜索表单提交的数据
    onSearch(val) {
      // 查询条件和分页数据合并
      const arr = Object.assign(this.queryParams, val);
      console.log(arr);
      this.queryParams.pageNum = 1;
      this.getList();
    },
     // 重置
     onReset(data) {
      console.log(data);
      this.queryParams.pageNum = 1;
      const arr = Object.assign(this.queryParams, data);
      console.log(this.queryParams);
      this.getList();
    },
    // 所有菜单节点数据
    getMenuAllCheckedKeys() {
      // 目前被选中的菜单节点
      let checkedKeys = this.$refs.menu.getCheckedKeys();
      // 半选中的菜单节点
      let halfCheckedKeys = this.$refs.menu.getHalfCheckedKeys();
      checkedKeys.unshift.apply(checkedKeys, halfCheckedKeys);
      return checkedKeys;
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      this.form = {
        roleId: undefined,
        roleName: undefined,
        roleKey: undefined,
        roleSort: 0,
        status: "0",
        menuIds: [],
        deptIds: [],
        menuCheckStrictly: true,
        deptCheckStrictly: true,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.open = true;
      this.title = "添加辅导员考核信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = true;
      this.title = "修改辅导员考核信息";
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.roleId != undefined) {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            updateRole(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            addRole(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$modal
        .confirm('是否确认删除角色编号为"' + roleIds + '"的数据项？')
        .then(function () {
          return delRole(roleIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handlePreview(file) {
      console.log(file, "上传");
    },
  },
};
</script>